﻿using UnityEngine;

namespace Gdmec.Util
{
    //https://blog.csdn.net/qq_35539447/article/details/80486247

    /// <summary>
    /// 贝塞尔曲线算法
    /// </summary>
    public class BezierUtil
    {
        //二次方的也不是很难理解，还是求插值，p0和p1的插值，p1和p2的插值，在求这两个插值(vector3)的插值
        // 二阶曲线

        /// <summary>
        /// 
        /// </summary>
        /// <param name="from">起点</param>
        /// <param name="h">期望高</param>
        /// <param name="to">终点</param>
        /// <param name="t">时间变化 0->1</param>
        /// <returns></returns>
        public static Vector3 Bezier(Vector3 from, Vector3 h, Vector3 to, float t)
        {
            Vector3 p0p1 = (1 - t) * from + t * h;
            Vector3 p1p2 = (1 - t) * h + t * to;
            Vector3 result = (1 - t) * p0p1 + t * p1p2;
            return result;
        }
    }
}
